/**
* @file
* @brief This file handles password encryption
*/
#include <stdlib.h>
#include <stdio.h>
#include "utils.h"

/**
* Print to user if wrong number of commandline arguments was given
*/
void print_usage()
{
        printf("Usage: encrypt_passwd PASSWORD [SALT]\n");
}

int main(int argc, char *argv[])
{
    char *passwd;
    char *salt;

    if(argc == 2)
    {
	passwd = argv[1];
	salt = NULL;
    }
    else if(argc == 3)
    {
	passwd = argv[1];
	salt = argv[2];
    }
    else
    {
	print_usage();
	return -1;
    }
    // Generate encrypter password
    char *encrypted_passwd = generate_encrypted_password(passwd, salt);
    if(encrypted_passwd == NULL)
    {
	printf("An error occured.\n");
	return -1;
    }
    // Print the encrypted password
    printf("%s\n", encrypted_passwd);
    return 0;
}
